<!DOCTYPE HTML>
<html>
<head>
    <title>接口文档管理</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <link rel="stylesheet" href="${contextPath}/css/default.css" type="text/css"/>
    <link rel="stylesheet" href="${contextPath}/css/theme-chalk.css" type="text/css"/>
    <script src="${contextPath}/jquery/jquery.min.js"></script>
    <script src="${contextPath}/vue/vue.global.js"></script>
    <script src="${contextPath}/vue/index.full.js"></script>
</head>
<body>
<div id="app">
    <p class="heading">&nbsp;&nbsp;接口文档管理</p>
    <div id="content">
        <table class="dataTable2" style="margin-left:0px;margin-top: 5px;">
            <tbody>
            <tr>
                <td valign="top">
                    <div style="height: 600px;width:500px;overflow-y: auto;">
                        <el-tree ref="tree"
                                 :data="menuData"
                                 show-checkbox
                                 node-key="apiId"
                                 :default-expanded-keys="defaultExpandedKeys" :default-checked-keys="defaultCheckedKeys"
                                 :props="menuDefaultProps">
                        </el-tree>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <input id="btn_export_html" type="button" style="width:150px;height:40px;font-size:20px" :value="btn_export_html"
                           @click="exportHtml()"/>
                    <input id="btn_export_pdf" type="button" style="width:150px;height:40px;font-size:20px;margin-left: 10px;" :value="btn_export_pdf"
                           @click="exportPdf()"/>
                    <input id="btn_test" type="button" style="width:150px;height:40px;font-size:20px;margin-left: 10px;" :value="btn_delete"
                           @click="deleteApi()"/>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <br>
    <br></div>
</body>

</html>
<script type="text/javascript">
    var contextPath = "${contextPath}";
    var appName = "${appName}";
    var menuData = JSON.parse('[${menuTree}]');
    const App = {
        el: '#app',
        data: function () {
            return {
                menuData: menuData,
                menuDefaultProps: {
                    children: 'childrens',
                    label: 'name',
                },
                filterText: '',
                defaultExpandedKeys: ['root'],
                btn_export_html:'导出HTML',
                btn_export_pdf:'导出PDF',
                btn_delete:'删除文档'
            };
        },
        methods: {
            exportHtml() {
                let apiIds = this.$refs.tree.getCheckedKeys();
                if (apiIds.length == 0) {
                    alert("请先选择接口");
                    return;
                }
                var postData = {};
                postData['appName'] = appName;
                postData['apiIds'] = apiIds;
                submitForm(contextPath+'/app/export?exportType=html', postData);
            },exportPdf() {
                let apiIds = this.$refs.tree.getCheckedKeys();
                if (apiIds.length == 0) {
                    alert("请先选择接口");
                    return;
                }
                var postData = {};
                postData['appName'] = appName;
                postData['apiIds'] = apiIds;
                submitForm(contextPath+'/app/export?exportType=pdf', postData);
            }, deleteApi() {
                var apiIds_ = this.$refs.tree.getCheckedKeys();
                if (apiIds_.length == 0) {
                    alert("请先选择接口");
                    return;
                }
                if(!confirm("你确定要删除选择的接口？")){
                    return;
                }
                var apiIds = null;
                for(var i in apiIds_){
                    if(apiIds==null){
                        apiIds = apiIds_[i];
                    }else{
                        apiIds += ","+apiIds_[i];
                    }
                }
                var reqParam = {"apiIds":apiIds,"appName":"${appName}"};
                $.ajax({
                    type: "POST",
                    async: true,
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    data:reqParam,
                    url:"${contextPath}/api/delete?ajaxTime="+new Date(),
                    success: function(res){
                        if(res.success == false){
                            alert(res.message);
                        }else{
                            alert("删除完成！");
                            location.href="${contextPath}/app/api-tree?appName=${appName}"
                        }
                    }
                });
            }
        },
        watch: {},
        mounted() {
        }
    };
    const app = Vue.createApp(App);
    app.use(ElementPlus);
    app.mount("#app");
</script>
<script src="${contextPath}/vue/utils.js"></script>
